package org.particles.gui;

import java.util.TimerTask;

/**
 * process worlds next state and repaints world. 
 */
public class WorldTimeTask extends TimerTask {
	private WorldPanel worldPanel;
	private boolean running = false;
	
	public boolean isRunning() {
		return running;
	}

	public void setRunning(boolean running) {
		this.running = running;
	}

	public WorldTimeTask(final WorldPanel worldPanel) {
		this.worldPanel = worldPanel;
	}
	
	@Override
	public void run() {
		if(!running) {
			return;
		}
		else {
			synchronized (worldPanel) {
				worldPanel.getWorld().nextState();
				worldPanel.repaint();
			}
		}
	}
}
